//---------------------------------------------------------
//  Title: extend.v
//  Module: extend
//  Function: Extends Immediate Operand
//  Coder: Mitchell Kline
//  Date Created: Apr 12, 2007
//---------------------------------------------------------

//------------------------Notes-------------------------                                                  
//    It is not always necessary to sign extend the       
//  immediate operand.  For instance, during an xori      
//  operation, an erroneous result would be computed      
//  if the immediate was sign extended.                  


module extend(ImmValue16,Signed,ImmValue32);

  input [15:0] ImmValue16;
  input Signed;

  output [31:0] ImmValue32;
  reg [31:0] ImmValue32;

  always @ (ImmValue16 or Signed) begin

    if (Signed) begin
      if (ImmValue16[15]) ImmValue32 = {16'hFFFF,ImmValue16};
      else ImmValue32 = {16'b0, ImmValue16};
    end
    else  ImmValue32 = {16'b0, ImmValue16};

  end
endmodule
